package com.example.httpdemo.http;

import com.example.httpdemo.net.ApiService;

public class ApiServiceHelper {


    private static ApiService apiService;

    public static ApiService getApiService() {
        if (apiService == null) {
            apiService = RetrofitClient.getRetrofit().create(ApiService.class);
        }
        return apiService;
    }



    //动态代理去创建apiservice，兼容多baseurl
//    private static Map<Class<?>, Object> serviceCache = new ConcurrentHashMap<>();
//
//    public static <T> T createService(Class<T> serviceClass) {
//        return (T) serviceCache.computeIfAbsent(serviceClass, cls ->
//                Proxy.newProxyInstance(
//                        serviceClass.getClassLoader(),
//                        new Class<?>[]{serviceClass},
//                        (proxy, method, args) -> {
//                            T service = RetrofitClient.getRetrofit().create(serviceClass);
//                            return method.invoke(service, args);
//                        })
//        );
//    }


}